﻿/**********************************************************************************
 * Description:     
 * MemberVariable:
 * Functions:       
 * Modify information:     
 * 2008-8-5     New           DuYaoHui     Create Class
 * 
 * ********************************************************************************/
using System;
using System.Web.UI.WebControls;
using System.Data;
using Fjaspx.Templet;
using Fjaspx.Common;
namespace Fjaspx.UI.Web
{
    public partial class Administrator_tag_tag_new : AdminPage
    {
        Tag Model = new Tag();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                SystemCms.AdminSesion();
                //绑定分类
                DdlMenu_bind();
                //模板列表绑定
                DropDownList_bind();

            }
        }
        //标签生成事件
        protected void LinkButton_stup_Click(object sender, EventArgs e)
        {
            if (CheckBox_page.Checked)
            {
                Label1.Visible = true;
                TextBox_pageSize.Visible = true;
            }
            else
            {
                Label1.Visible = false;
                TextBox_pageSize.Visible = false;
            }
            if (CheckBox_sql.Checked)
            {
                TextBox_SQL.Visible = true;
            }
            else { TextBox_SQL.Visible = false; }

            Model.NewsCount = TextBox_top.Text.Trim();
            Model.TitleNum = TextBox_count.Text.Trim();
            if (this.DdlMenu.SelectedValue != "")
            {
                Model.NewsType = this.DdlMenu.SelectedValue;
            }
            if (CheckBox_ding.Checked) { Model.Ding = "ture"; } else { Model.Ding = null; }
            if (CheckBox_tuijian.Checked) { Model.Tuijian = "ture"; } else { Model.Tuijian = null; }
            if (this.DropDownList_list.SelectedValue != "")
            {
                Model.Templet = this.DropDownList_list.SelectedValue;
            }

            if (CheckBox_page.Checked)
            {
                Model.pg = true;
                Model.PageSize = TextBox_pageSize.Text.Trim();
            }
            Model.SQL = null;
            if (CheckBox_sql.Checked)
            {
                Model.SQL = TextBox_SQL.Text.Trim();
                Model.Ding = null;
                Model.Tuijian = null;
                Model.NewsType = null;
                Model.PageSize = null;
            }

            TextBox_HTML.Text = Model.get_TAG();
        }

        #region 数据绑定
        void DdlMenu_bind()
        {
            DataSet ds = new Fjaspx.Sys.Bll.ROYcms_class().GetClassList(0);

            this.DdlMenu.Items.Clear();
            this.DdlMenu.Items.Add(new ListItem("请选择所属分类", ""));
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                int ClassTj = Convert.ToInt32(dr["ClassTj"]);
                string Id = dr["Id"].ToString().Trim();
                string ClassName = dr["ClassName"].ToString().Trim();

                if (ClassTj == 1)
                {
                    this.DdlMenu.Items.Add(new ListItem(ClassName, Id));

                }
                else
                {
                    ClassName = "├ " + ClassName;
                    ClassName = Fjaspx.Common.StringPlus.StringOfChar(ClassTj - 1, "　") + ClassName;

                    this.DdlMenu.Items.Add(new System.Web.UI.WebControls.ListItem(ClassName, Id));
                }
            }

        }
        #endregion

        //标签预览事件
        protected void LinkButton_star_Click(object sender, EventArgs e)
        {
            Fjaspx.Sys.Model.ROYcmsConfig _Configs =Fjaspx.Config.ROYcmsConfig.Get_Config();
            Fjaspx.Templet.TemplateTag TemplateTag = new Fjaspx.Templet.TemplateTag(_Configs);
            //TemplateTag.pageHost = "/";
            Label_inter_HTML.Text = TemplateTag.loopPage(TemplateTag.LoopTag(TextBox_HTML.Text));
        }

        //模板列表绑定
        void DropDownList_bind()
        {
            Fjaspx.Sys.Bll.ROYcms_template bll = new Fjaspx.Sys.Bll.ROYcms_template();
            DropDownList_list.DataSource = bll.GetList("class_name='show' and y = '0' ");
            DropDownList_list.DataTextField = "name";
            DropDownList_list.DataValueField = "bh";
            DropDownList_list.DataBind();
            DropDownList_list.Items.Insert(0, new ListItem("◆请选择模板◆", ""));//插入空项，此举必须放到数据绑定之后
        }
    }
}